<html>
<head><title>CS143 Project 1B Chuchu Wu</title></head>
<body>
<h3>
<p>CS143 Project 1B</p>
Chuchu Wu
</h3>
Type an SQL query in the following box:
<p>
<form action="query.php" method="GET">
<textarea name="query" cols="60" rows="8"></textarea>
<input type="submit" value="Submit" />
</form>
</p>

<?php
$db_connection = mysql_connect("localhost", "cs143", "");
mysql_select_db("CS143", $db_connection);
if($_GET["query"]!=Null)
{
echo "<h3>Results from MySQL:</h3>";
echo "<table border=1 cellspacing=1 cellpadding=2>";
$query = $_GET["query"];
$result = mysql_query($query, $db_connection);
$j=0;
echo "<tr align=center>";
while($j < mysql_num_fields($result))
{
$column=mysql_fetch_field($result, $j);
echo "<td><b>".$column->name."</b></td>";
$j++;
}

while($row = mysql_fetch_row($result))
{
	echo "<tr align=center>";
	$i=0;
	while($i < mysql_num_fields($result))
	{
		if($row[$i]==Null) print "<td>N/A</td>";
		else print "<td>$row[$i]</td>";
		$i++;
	}
	print "</tr>";
}



}
mysql_close($db_connection);


?>

</body>
</html>